package phoenix.web.page_objects.crm;

import org.openqa.selenium.WebElement;
import org.testng.TestException;
import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.PageBaseWebExt;
import phoenix.core.config.extensions.ConfigExt;
import phoenix.web.locators.base.crm.BrowseLetterLocatorsBase;
import phoenix.web.locators.base.crm.WelcomeLetterLocatorsBase;

public class BrowseMailPage extends PageBaseWebExt
{
	/**
	 * Initializes BrowseMailPage
	 * @param p_manager PhoenixManager instance
	 */
	public BrowseMailPage(PhoenixManager p_manager)
	{
		super(p_manager);
	}

	public BrowseLetterLocatorsBase elements()
	{
		switch (manager.testModel().getSiteName())
		{
			case ConfigExt.SITE_ID_BENAUGHTY:
			{
				return new phoenix.web.locators.benaughty.crm.BrowseLetterLocators();
			}
			case ConfigExt.SITE_ID_MATUREDATING:
			{
				return new phoenix.web.locators.maturedating.crm.BrowseLetterLocators();
			}
			case ConfigExt.SITE_ID_NAUGHTYFEVER:
			{
				return new phoenix.web.locators.naughtyfever.crm.BrowseLetterLocators();
			}
			case ConfigExt.SITE_ID_WILDBUDDIES:
			{
				return new phoenix.web.locators.wildbuddies.crm.BrowseLetterLocators();
			}
			case ConfigExt.SITE_ID_FLIRT:
			{
				return new phoenix.web.locators.flirt.crm.BrowseLetterLocators();
			}
			case ConfigExt.SITE_ID_CLICKANDFLIRT:
			{
				return new phoenix.web.locators.clickandflirt.crm.BrowseLetterLocators();
			}
			case ConfigExt.SITE_ID_LOCALSGOWILD:
			{
				return new phoenix.web.locators.localsgowild.crm.BrowseLetterLocators();
			}
			case ConfigExt.SITE_ID_MATUREAFFECTION:
			{
				return new phoenix.web.locators.maturedating.crm.BrowseLetterLocators();
			}
			default:
			{
				return null;
			}
		}
	}

	/**
	 * Returns list of subjects for Welcome letter
	 * @return String[]
	 */
	public String[] pageSubjects(String p_userName)
	{
		switch (manager.testModel().getSiteName())
		{
			case ConfigExt.SITE_ID_BENAUGHTY:
			{
				return new phoenix.web.test_objects.data_providers.crm.benaughty.LetterSubject().browseLetter(p_userName);
			}
			case ConfigExt.SITE_ID_MATUREDATING:
			{
				return new phoenix.web.test_objects.data_providers.crm.maturedating.LetterSubject().browseLetter(p_userName);
			}
			case ConfigExt.SITE_ID_NAUGHTYFEVER:
			{
				return new phoenix.web.test_objects.data_providers.crm.naughtyfever.LetterSubject().browseLetter(p_userName);
			}
			case ConfigExt.SITE_ID_WILDBUDDIES:
			{
				return new phoenix.web.test_objects.data_providers.crm.wildbuddies.LetterSubject().browseLetter(p_userName);
			}
			case ConfigExt.SITE_ID_FLIRT:
			{
				return new phoenix.web.test_objects.data_providers.crm.flirt.LetterSubject().browseLetter(p_userName);
			}
			case ConfigExt.SITE_ID_CLICKANDFLIRT:
			{
				return new phoenix.web.test_objects.data_providers.crm.clickandflirt.LetterSubject().browseLetter(p_userName);
			}
			case ConfigExt.SITE_ID_LOCALSGOWILD:
			{
				return new phoenix.web.test_objects.data_providers.crm.localsgowild.LetterSubject().browseLetter(p_userName);
			}
			case ConfigExt.SITE_ID_MATUREAFFECTION:
			{
				return new phoenix.web.test_objects.data_providers.crm.maturedating.LetterSubject().browseLetter(p_userName);
			}
			default:
			{
				return null;
			}
		}
	}

	public String getPageContent(String p_email, String p_userName)
	{
		String subject[] = this.pageSubjects(p_userName);
		return manager.mail().getMessageContent(subject, p_email);
	}

	public String getTextAutologin()
	{
		wd().waitForPresence(elements().linkAutologin, "Browse letter, link");
		wd().wait(2);
		String text = wd().getAttribute(elements().linkAutologin, "href");
		log().info(text);
		return text;
	}

	public WebElement getElementAutologin()
	{
		return manager.wd().getWebElement(elements().linkAutologin);
	}
}
